package com.yuanfeng.job.job;


import com.yuanfeng.commoms.util.DateUtils;
import com.yuanfeng.job.dto.BusinessOvertimeOrderDTO;
import com.yuanfeng.job.mapper.UpdateOrderStatusMapper;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 超过48小时售后退货订单商家未处理 自动同意
 */
public class ReturnOrderHandleJob implements BaseJob {

    private static final Logger logger = LoggerFactory.getLogger(RefundOrderHandleJob.class);
    @Autowired
    UpdateOrderStatusMapper updateOrderStatusMapper;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        // 查询超过48小时商家未处理的订单
        List<BusinessOvertimeOrderDTO> pojoList = updateOrderStatusMapper.queryTuiHuoOrderNotHandle();
        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String finishTime = dateformat.format(new Date());
        Map<String, Object> orderGoodsMap = new HashMap<String, Object>();
        for(BusinessOvertimeOrderDTO pojo : pojoList) {

            orderGoodsMap.put("returnCode", pojo.getReturnCode());
            orderGoodsMap.put("returnShopHandle", 2);
            orderGoodsMap.put("returnState", 2);
            orderGoodsMap.put("returnShopMessage", "商家超时未处理,自动同意-->买家填写物流");
            orderGoodsMap.put("returnShopTime", finishTime);
            updateOrderStatusMapper.updateOrderReturnById(orderGoodsMap);

        }
        logger.info("更新超过48小时商家未处理售后退货订单  更新时间" + DateUtils.getNowDate());

    }

}
